package com.pe.cineplanet.proyectocine.repository.hibernate;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.pe.cineplanet.proyectocine.domain.PrecioLocal;
import com.pe.cineplanet.proyectocine.repository.PrecioLocalRepository;
 
@Repository
public class PrecioLocalRepositoryHibernate  extends HibernateDaoSupport 
implements PrecioLocalRepository {
	
	//constructor
	@Autowired
	public PrecioLocalRepositoryHibernate(SessionFactory sessionFactory) {
		setSessionFactory(sessionFactory);
	}

	public List<PrecioLocal> obtenerPrecioLocales() {
		return getHibernateTemplate().find("from PrecioLocal");  
	}

	public PrecioLocal obtenerPrecioLocal(int id_Local) {
		return (PrecioLocal) getSession().createQuery("from PrecioLocal u where u.id_Local=?").setInteger(0, id_Local).uniqueResult();
	}

	public void grabarPrecioLocal(PrecioLocal obj) {
		getHibernateTemplate().saveOrUpdate(obj);
		
	}

	public void removerPrecioLocal(int id_Local) {
		PrecioLocal obj = obtenerPrecioLocal(id_Local);
		getHibernateTemplate().delete(obj);
		
	}

}
